** File creating tables of descriptives on location choice by child status **

//combine race-specific simulated data into single files for later anslysis
local files `"baseline cfact_natsub cfact_locsub cfact_halfccc cfact_nolock cfact_noparent cfact_tweakccc"'

foreach file in `files'{
	import delimited "$dir/Model/simulated_data/simulated_data_`file'_3.csv", clear
	gen v25 = 2
	tempfile blacks
	save `blacks'

	import delimited "$dir/Model/simulated_data/simulated_data_`file'_2.csv", clear
	gen v25 = 1
	append using `blacks'
	save "$temp/simulated_data_`file'_combined", replace
}


//whites
import delimited "$dir/Model/simulated_data/simulated_data_base_2.csv", clear
gen race = 1
tempfile whites
save `whites'

import delimited "$dir/Model/simulated_data/simulated_data_base_3.csv", clear
gen race = 2
append using `whites'
export delimited "$dir/Model/simulated_data/simulated_data_base_combined.csv", replace novarn



global resultsDIR "$output"



local sample = 2
local letter "a"


if `sample'== 1{
use "$temp/psid_estimation_sample", clear
gen sim = 1
}


if `sample' == 2{
	*** GARRETT: ADD NAME OF SIMULATION SAMPLE
	import delimited "$model/simulated_data/simulated_data_base_combined.csv", clear
	ren v1 uniqid
	ren v2 year
	ren v3 mu
	ren v4 e
	ren v5 m
	ren v6 p
	ren v7 l
	ren v8 age
	ren v9 x
	ren v10 ac
	ren v11 f
	ren v12 lp_type
	ren v13 h
	ren v14 wage
	ren v15 l_prime
	ren v16 sim
	local letter "b"
}

sort uniqid sim year

//garrett messed up some stuff when creating the estimation sample in terms of how variables are coded (indices vs. values). Adjust here.
ds e m p f
foreach var in `r(varlist)'{
	replace `var' = `var' - 1
}
replace ac = ac - 2
replace x = x-1 //experience: 0 is the first index 
replace age = age+21
replace wage = . if wage == 0 //not observed if zero

label define loclab 1 "parent" 2 "low cost, low wage" 3 "low cost, high wage" 4 "high cost, low wage" 5 "high cost, high wage"
label values l loclab
label var l location

// Creating a measure that combines parent and cost-structure location
g loc_current = .
replace loc_current = lp_type if l == 1
replace loc_current = l+3 if l != 1


label define loc_lab 1 "parent LC LW" 2 "parent LC HW" 3 "parent HC LW" 4 "parent HC HW" 5 "no parent LC LW" 6 "no parent LC HW" 7 "no parent HC LW" 8 "no parent HC HW"
label values loc_current loc_lab
label var loc_current "expanded location types"

cap drop loc_prev
cap drop loc_next
sort uniqid sim year
by uniqid sim: g loc_prev = loc_current[_n-1]
by uniqid sim: g loc_next = loc_current[_n+1]
// Variables indicating if moving next period or moved last period
gen mig = (l_prime<6)
//g move_next= loc_current != loc_next //this was incorrect: one can move to a different state of the same time (e.g. high cost, high wage) and this would flag that as a non-move
g move_next = (l_prime<6) //correct way to define migration
g move_prev= loc_current != loc_prev
label values loc_prev loc_lab
label values loc_next loc_lab

// Creating Child Types
g child_type = .
replace child_type = 0 if ac == -1 & f == 0
replace child_type = 0.5 if ac == -1 & f == 1
replace child_type = 1 if ac != -1
*label define c_lab 0 "No Kids, Not Pregnant" 0.5 "No Kids, Pregnant" 1 "Kids"
*label values child_type c_lab


// Parent indicator
g parent = l == 1
sort uniqid sim year
cap drop parent_next
cap drop parent_prev
by uniqid sim: g parent_next = parent[_n+1]
by uniqid sim: g parent_prev = parent[_n-1]

// Dummies for cost type
g liveLCLW= (loc_current == 1 | loc_current == 5)
g liveLCHW= (loc_current == 2 | loc_current == 6)
g liveHCLW= (loc_current == 3 | loc_current == 7)
g liveHCHW= (loc_current == 4 | loc_current == 8)


// Just cost type, no break down by parent
g loc_cost = .
replace loc_cost = lp_type if l == 1
replace loc_cost= l-1 if l != 1
sort uniqid sim year 
by uniqid sim: g loc_cost_next =loc_cost[_n+1]

//Conditional on marital status, work status
g h_marr = .
replace h_marr = h if (m == 1 | m == 2)

g h_nomarr = .
replace h_nomarr = h if m == 0

// What percent of our sample lives in each cost-wage group? 
eststo clear
*Overall

estpost summ live*
eststo model1
* By parent's loc
estpost summ live* if parent == 1
eststo model2
estpost summ live* if parent == 0
eststo model3
 
* By Educ

estpost summ live* if e == 1
eststo model4
estpost summ live* if e == 0
eststo model5

/* By Young Child vs. No Young Child

estpost summ live* if childtype == 0
eststo model6
estpost summ live* if childtype == 0.5
eststo model7
estpost summ live* if childtype == 1
eststo model8
*/
* By Young Child & Parent vs. Young Child & No Parent
estpost summ live* if child_type == 0 & parent == 1
eststo model6
estpost summ live* if child_type == 0.5& parent == 1
eststo model7
estpost summ live* if child_type == 1& parent == 1
eststo model8
estpost summ live* if child_type == 0 & parent == 0
eststo model9
estpost summ live* if child_type == 0.5& parent == 0
eststo model10
estpost summ live* if child_type == 1& parent == 0
eststo model11


label var liveLCLW `"Low Cost Child Care Low Wage"'
label var liveLCHW `"Low Cost Child Care High Wage"' 
label var liveHCLW`"High Cost Child Care Low Wage"'
label var liveHCHW `"High Cost Child Care High Wage"'

/*

esttab model1 model2 model3 model6 model7 model8 model9 model10 model11 ///
using "${resultsDIR}\CostofLivingDem`sample'.csv" , main(mean) aux(sd) ///
		nonumbers ///
mtitles("All" "Parent Loc." "Not Parent Loc."  "No Kids Parent Loc." "Pregnant Parent Loc." "Kids Parent Loc." "No Kids Not Parent Loc." "Pregnant  Not Parent Loc. " "Kids Not Parent Loc." ) unstack ///
label title("Location Choices by Child Care Costs and Wage Types") replace

esttab model1 model2 model3  model6 model7 model8 model9 model10 model11 ///
using "${resultsDIR}\CostofLivingDem`sample'.tex" , main(mean) aux(sd) ///
		nonumbers ///
mtitles("All" "Parent Loc." "Not Parent Loc."  "No Kids Parent Loc." "Pregnant Parent Loc." "Kids Parent Loc." "No Kids Not Parent Loc." "Pregnant  Not Parent Loc. " "Kids Not Parent Loc." )  unstack ///
label title("Location Choices by Child Care Costs and Wage Types") replace
*/

// Of movers, what proportion...
eststo clear
* Move from or to their parent
estpost summ parent parent_next if mig
eststo modelA 
* Move to their parent by kid type
estpost summ parent parent_next if mig & child_type == 0 & loc_next != .
eststo modelB
estpost summ parent parent_next if mig & child_type == 0.5& loc_next != .
eststo modelC
estpost summ parent parent_next if mig & child_type == 1& loc_next != .
eststo modelD

label var parent `"Origin: Parent "'
label var parent_next  `"Destination: Parent"' 

/*
esttab modelA modelB modelC modelD ///
using "${resultsDIR}\MoveDirectionParent`sample'.csv" , main(mean) aux(sd) ///
		nonumbers ///
mtitles("All"   "No Kids" "Pregnant" "Kids") unstack ///
label title("Percent of Moves to and from Parent's Location, by Fertility Status") replace

esttab modelA modelB modelC modelD ///
using "${resultsDIR}\MoveDirectionParent`sample'.tex" , main(mean) aux(sd) ///
		nonumbers ///
mtitles("All"   "No Kids" "Pregnant" "Kids") unstack ///
label title("Percent of Moves to and from Parent's Location, by Fertility Status") replace
*/
* Transition between different cost-wage overall
// NOTE: POSSIBLY TOO FEW BY GROUP TO USE AS MOMENT TO MATCH
tab loc_cost loc_cost_next  if move_next == 1, r

* Transition between different cost-wage and parent 
// NOTE: TOO FEW BY GROUP TO USE AS MOMENT TO MATCH
bys parent: tab loc_cost loc_cost_next  if move_next == 1, r
bys parent_next: tab loc_cost loc_cost_next  if move_next == 1, r

// Of women, what proportion ...


eststo clear
* Work with young child vs. work without young child
estpost summ h h_nomarr h_marr if child_type == 0
eststo model1
estpost summ h h_nomarr h_marr if child_type == 0.5
eststo model2
estpost summ h h_nomarr h_marr if child_type == 1
eststo model3
* Work with young child vs. work without young child by child care-wage profile overall
*bys loc_cost: tab h child_type, col
*  Work with young child vs. work without young child  by parent type
estpost summ h h_nomarr h_marr if child_type == 0 & parent == 1
eststo model4
estpost summ h h_nomarr h_marr if child_type == 0.5 & parent == 1
eststo model5
estpost summ h h_nomarr h_marr if child_type == 1 & parent == 1
eststo model6
estpost summ h h_nomarr h_marr if child_type == 0 & parent == 0
eststo model7
estpost summ h h_nomarr h_marr if child_type == 0.5 & parent == 0
eststo model8
estpost summ h h_nomarr h_marr if child_type == 1 & parent == 0
eststo model9


label var h `"% of All Women Working "'
label var h_marr  `"% of Married Women Working "' 
label var h_nomarr  `"% of Unmarried Women Working "' 

/*
esttab model1 model2 model3 model4 model5 model6 model7 model8 model9 ///
using "${resultsDIR}\Table_10`letter'.csv" , main(mean) aux(sd) ///
		nonumbers ///
mtitles("No Kids" "Pregnant" "Kids" "No Kids Parent Loc." "Pregnant Parent Loc." "Kids Parent Loc." "No Kids Not Parent Loc." "Pregnant  Not Parent Loc. " "Kids Not Parent Loc." ) unstack ///
label title("Location Choices by Child Care Costs and Wage Types") replace
*/
esttab model1 model2 model3  model4 model5 model6 model7 model8 model9 ///
using "${resultsDIR}\Table_10`letter'.tex" , main(mean) aux(sd) ///
		nonumbers ///
mtitles("No Kids" "Pregnant" "Kids" "No Kids Parent Loc." "Pregnant Parent Loc." "Kids Parent Loc." "No Kids Not Parent Loc." "Pregnant  Not Parent Loc. " "Kids Not Parent Loc." ) unstack ///
label title("Location Choices by Child Care Costs and Wage Types") replace

